Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove export handling from getExportPaths for wildcard matching #244

Merged
merged 20 commits into from
Sep 5, 2023

Conversation

devjiwonchoi
Copy link
Contributor

@devjiwonchoi devjiwonchoi commented Aug 17, 2023

Feature Explanation

The Wildcard Exports feature allows the user to set exports['./*'], and bunchee maps the wildcard with the Exportable Entries.

Requirements

The Exportable Entries a.k.a. exportables need to be inside the root src directory.

Exportable Entries

  1. Files with allowed extension js | cjs | mjs | jsx | ts | tsx | cts | mts - excluding index (entry for ['.']).
  2. Folders containing index file(s) with allowed extension.

Usage

Folder Structure:

- my-lib/
  |- src/
    |- a/
      |- index.ts
    |- b.ts
    |- index.ts
  |- package.json

package.json

{
  "name": "my-lib",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    },
    "./*": {
      "types": "./dist/*.d.ts",
      "import": "./dist/*.js"
    }
  }
}

Will be treated as:

{
  "name": "my-lib",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    },
    "./a": {
      "types": "./dist/a/index.d.ts",
      "import": "./dist/a/index.js"
    }
    "./b": {
      "types": "./dist/b.d.ts",
      "import": "./dist/b.js"
    }
  }
}

One design improvement could be: keep getExportPaths simple, that reciving a resolved exports map instead of cwd and doing cwd operation

Resolves: #243

@devjiwonchoi devjiwonchoi marked this pull request as ready for review August 18, 2023 11:44
@huozhi huozhi changed the title refac(wildcard): remove export handling from getExportPaths refactor: remove export handling from getExportPaths for wildcard matching Aug 20, 2023
src/constants.ts Outdated Show resolved Hide resolved
src/bundle.ts Outdated Show resolved Hide resolved
@devjiwonchoi
Copy link
Contributor Author

devjiwonchoi commented Aug 21, 2023

@huozhi Could you help me out on simplifying this code?

Objective

Return resolved exports by replacing resolved wildcard exports to the current './*'

Code

const resolvedExports = Object.assign(
  {},
  exports,
  ...resolvedWildcardExports, // typeof ExportCondition[]
  exports,
)
delete resolvedExports['./*']
return resolvedExports

src/experimental/wildcard.ts Outdated Show resolved Hide resolved
src/experimental/wildcard.ts Outdated Show resolved Hide resolved
src/lib/wildcard.ts Outdated Show resolved Hide resolved
Copy link
Owner

@huozhi huozhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Thank you!!

@huozhi huozhi merged commit c5a54f1 into huozhi:main Sep 5, 2023
3 checks passed
@devjiwonchoi devjiwonchoi deleted the refac/wildcard-exports branch September 5, 2023 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor getExportPaths
2 participants